<!--
 * @Author: your name
 * @Date: 2022-04-21 21:34:14
 * @LastEditTime: 2022-04-22 11:22:48
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\4.21.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
 * @param {number[]} nums
 * @return {number}
 */
        var maxRotateFunction = function (nums) {
            let ans = 0, result = 0, n = nums.length;
            for (let i = 0; i < n; i++) {
                ans += nums[i];
                result += i * nums[i];
            }
            for (let i = 0; i < n - 1; i++) {
                let num = result, right = nums.pop();
                ans -= right;
                num -= (n - 1) * right;
                num += ans;
                nums.unshift(right);
                ans += right;
                result = Math.max(result, num);
            }
            return result;
        };
        console.log(maxRotateFunction([4,3,2,6]));
    </script>
</body>

</html>